package server;

import java.util.LinkedList;
import java.util.List;

public class GetRadomValue
{
    private LinkedList<String> valueList = new LinkedList<String>();
    
    private LinkedList<String> valueList1 = new LinkedList<String>();
    
    private LinkedList<String> valueList2 = new LinkedList<String>();
    
    private LinkedList<String> valueList3 = new LinkedList<String>();
    
    private LinkedList<String[]> arrayList = new LinkedList<String[]>();
    
    private String date[] = new String[21];
    
    public final static int MAX_ArrayLIST_SIZE = 25;
    
    public final static int MAX_LIST_SIZE = 23;
    
    private static GetRadomValue intance = new GetRadomValue();
    
    private int discern;
    
    private boolean ifUse = false;
    
    private GetRadomValue()
    {
    }
    
    public static GetRadomValue getInstance()
    {
        return intance;
    }
    
    @SuppressWarnings("unchecked")
    public synchronized List getList()
    {
        return valueList;
    }
    
    public synchronized void pushValue(String value)
    {
        if (valueList.size() >= MAX_LIST_SIZE)
        {
            valueList.poll();
        }
        valueList.offer(String.valueOf(Float.parseFloat(value) / 100));
    }
    
    public synchronized void pushValue1(String value1)
    {
        if (valueList1.size() >= MAX_LIST_SIZE)
        {
            valueList1.poll();
        }
        valueList1.offer(value1);
    }
    
    public synchronized void pushValue2(String value2)
    {
        if (valueList2.size() >= MAX_LIST_SIZE)
        {
            valueList2.poll();
        }
        valueList2.offer(String.valueOf(Float.parseFloat(value2) / 10));
    }
    
    public synchronized void pushValue3(String value3)
    {
        if (valueList3.size() >= MAX_LIST_SIZE)
        {
            valueList3.poll();
        }
        valueList3.offer(String.valueOf(Float.parseFloat(value3) / 10));
    }
    
    public synchronized void pushArrayValue(String[] value)
    {
        int idx = -1;
        for (int i = 0; i < arrayList.size(); i++)
        {
            String macArray = arrayList.get(i)[6];
            if (value[6] == null)
            {
                System.out.println("value[6]是空的");
            }
            if (value[6].equals(macArray))
            {
                idx = i;
                break;
            }
        }
        if (idx > -1)
        {
            arrayList.remove(idx);
        }
        if (arrayList == null)
        {
            System.out.println("arrayList是空的");
        }
        else
        {
            System.out.println("arrayList of size:" + arrayList.size());
        }
        if (value == null)
            System.out.println("value是空的");
        arrayList.offer(value);
        
    }
    
    public void pushValue(String value, int discern)
    {
        
        date[discern] = value;
        System.out.println(date[discern]);
    }
    
    public LinkedList getRadomValue()
    {
        LinkedList list = new LinkedList();
        int size = valueList.size();
        for (int j = 0; j < size; j++)
        {
            double[] data = {j, Double.parseDouble(valueList.get(j))};
            list.add(j, data);
        }
        return list;
    }
    
    public LinkedList getRadomValue1()
    {
        LinkedList list = new LinkedList();
        int size = valueList1.size();
        for (int j = 0; j < size; j++)
        {
            double[] data = {j, Double.parseDouble(valueList1.get(j))};
            list.add(j, data);
        }
        return list;
    }
    
    public LinkedList getRadomValue2()
    {
        LinkedList list = new LinkedList();
        int size = valueList2.size();
        for (int j = 0; j < size; j++)
        {
            double[] data = {j, Double.parseDouble(valueList2.get(j))};
            list.add(j, data);
        }
        return list;
    }
    
    public LinkedList getRadomValue3()
    {
        LinkedList list = new LinkedList();
        int size = valueList3.size();
        for (int j = 0; j < size; j++)
        {
            double[] data = {j, (Double.parseDouble(valueList3.get(j)))};
            list.add(j, data);
        }
        return list;
    }
    
    public String[] getArrayValue(String mac)
    {
        if (mac.equals(date[6]))
        {
            return date;
        }
        else
        {
            return null;
        }
        
    }
    
    public String[] getArrayListValue(String mac)
    {
        for (int i = 0; i < arrayList.size(); i++)
        {
            String macArray = arrayList.get(i)[6];
            if (mac.equals(macArray))
            {
                return arrayList.get(i);
            }
        }
        return null;
        
    }
    
    public int getDiscern()
    {
        return discern;
    }
    
    public void setDiscern(int discern)
    {
        this.discern = discern;
    }
    
    public boolean isIfUse()
    {
        return ifUse;
    }
    
    public void setIfUse(boolean ifUse)
    {
        this.ifUse = ifUse;
    }
    
}
